/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelWarstwa.java
 *
 * Created on 2011-05-14, 11:11:38
 */

package App.widoki;

import App.kontrolery.IObslugaWyboruWarstwy;
import java.awt.Color;
import skladowisko.Kontener;
import skladowisko.Warstwa;

/**
 *
 * @author Krzysiek
 */
public class PanelWarstwa extends javax.swing.JPanel {

    private IObslugaWyboruWarstwy nadzorca = null;
    Warstwa warstwa;

    private static final Color KOLOR_PELNE = Color.blue;
    private static final Color KOLOR_PUSTE = Color.white;
    private static final Color KOLOR_NAJECHANE = Color.LIGHT_GRAY;
    private static final Color KOLOR_WYBRANE = Color.RED;

    private Color kolorAktualny = Color.white;

    private boolean klikniete = false;

    /** Creates new form PanelWarstwa */
    public PanelWarstwa(Warstwa warstwa)
    {
        initComponents();
        this.warstwa = warstwa;

        if(warstwa.isPuste())
        {
            this.setBackground(KOLOR_PUSTE);
            kolorAktualny = KOLOR_PUSTE;
        }
        else
        {
            this.setBackground(KOLOR_PELNE);
            kolorAktualny = KOLOR_PELNE;
        }
    }

    public void ustawNadzorce(IObslugaWyboruWarstwy nadzorca)
    {
        this.nadzorca = nadzorca;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setBackground(new java.awt.Color(51, 51, 255));
        setBorder(new javax.swing.border.MatteBorder(null));
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                formMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                formMouseExited(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 150, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 41, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void formMouseEntered(java.awt.event.MouseEvent evt)//GEN-FIRST:event_formMouseEntered
    {//GEN-HEADEREND:event_formMouseEntered
        if(!klikniete)
        {
        this.setBackground(KOLOR_NAJECHANE);
        this.repaint();
        }
    }//GEN-LAST:event_formMouseEntered

    private void formMouseExited(java.awt.event.MouseEvent evt)//GEN-FIRST:event_formMouseExited
    {//GEN-HEADEREND:event_formMouseExited
        if(!klikniete)
        {
        this.setBackground(kolorAktualny);
        this.repaint();
        }
    }//GEN-LAST:event_formMouseExited

    private void formMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_formMouseClicked
    {//GEN-HEADEREND:event_formMouseClicked
        this.setBackground(KOLOR_WYBRANE);
        nadzorca.obslugujWyborWarstwy(this);
        this.klikniete = true;
        this.repaint();
    }//GEN-LAST:event_formMouseClicked

    public void setKlikniete(boolean klikniete)
    {
        this.klikniete = klikniete;
        
        if(klikniete)
        {
             this.setBackground(KOLOR_WYBRANE);
        }
        else
        {
            this.setBackground(kolorAktualny);
        }
        this.repaint();
    }
    
    public Kontener getKontener()
    {
        return this.warstwa.getKontener();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
